// pages/self/pastAppoint/pastAppoint.js
Page({

  /**
 * 页面的初始数据
 */
data: {
    classfiySelect:"tre",
    doctorId:"",
    fieldid:"",
    rigId:'01',
    rightData: [/*{
      id:"01",
      title:"已就诊",
      text:"ninhiywesdjnsjkj被封杀了孔明借东风后面昆仑山搭街坊不会s",
      time:"2020-5-1",
      url:"/pages/images/诊所.png",
      right:1,
    },

    {
      id:"02",
      title:"未就诊",
      text:"ninhiywesdjnsjkjvfrgbhnyjumkmjhs",
      time:"2020-5-1",
      url:"/pages/images/诊所.png",
      right:1,
    },
    {
      id:"01",
      title:"已逾期",
      text:"ninhiywesdjnsjkjvfrgbhnyjumkmjhs",
      time:"2020-5-1",
      url:"/pages/images/15.png",
      right:'true',
    },  
    {
      id:"01",
      title:"预约成功通知",
      text:"ninhiywesdjnsjkjvfrgbhnyjumkmjhs",
      time:"2020-5-1",
      url:"/pages/images/15.png",
      right:'true',
    }*/
  ],
},

/**
 * 生命周期函数--监听页面加载
 */
onLoad: function (options) {
 /* this.setData({
    classfiySelect: this.data.leftText[0].id,
  })*/
  console.log(getApp().globalData.doctorId)
  var that = this;
  wx.request({
    url:  getApp().globalData.url+'patientshowmessage', // 仅为示例，并非真实的接口地址
    method: 'GET',
    data: {
      unitphone:getApp().globalData.unitphone
    },
    header: {
      'content-type': 'application/x-www-form-urlencoded' // 默认值
    },
    success(res) {  
      let fi={};
      let first1=[];
     for(let i=0;i<res.data.length;i++) 
     {
         var messageIds="";
         var messageDateTimes="";
         var messageMarks="";
         var times="";
         var type="";
         var titles="";
         var texts="";
         var doctorRanks="";
         var doctorNames="";
         var urls="";
          messageIds=res.data[i].messageInform.messageId;
          messageDateTimes=res.data[i].messageInform.messageDateTimes;
          messageMarks=res.data[i].messageInform.messageMark;
          times=res.data[i].messageInform.bookDate + " " + res.data[i].messageInform.bookTime;
          type=res.data[i].messageInform.messageMark;
          doctorNames = res.data[i].doctorInfoForm.doctorName;
          doctorRanks = res.data[i].doctorFieldForm.doctorField;
          console.log(res.data)
         if(type=="1")
         {
           titles="预约成功通知";
           texts="尊敬的病友您好，您已成功预约"+times+"，"+doctorRanks+"科室"+
           doctorNames+"医生"+"请您及时就诊！";
           urls="/pages/images/诊所.png";
         }
         else if(type=="3"){
          titles="预约取消通知";
          urls="/pages/images/15.png";
          if(res.data[i].messageMark!=0)
          {
            texts="尊敬的病友您好，您已成功取消"+times+"，"+doctorRanks+"科室"+
          doctorNames+"医生的预约！";
          }
          else{
            texts="尊敬的病友您好，您预约的"+times+"，"+doctorRanks+"科室"+
            doctorNames+
            "医生，我们抱歉的通知您的预约已经被医生取消";
          }
         }
        fi={"id":messageIds,"title":titles,"text":texts,"time":messageDateTimes,"url":urls,"right":messageMarks};
        first1.push(fi);
     }
     that.setData({
      "rightData":first1
    })
    },
    fail(res){
      wx.showToast({
        title: '网络连接失败，请重新尝试',
        icon:'none'
      })
    }
  })
},
toRecords: function(e){
  console.log(e);
  var chooseId=e.currentTarget.dataset.id;
  var chooseText=e.currentTarget.dataset.text;
  console.log(chooseId);
  getApp().globalData.appointText=chooseText;
  console.log(getApp().globalData.appointText);
  var that = this;
  wx.request({
    url:  getApp().globalData.url+'patientOrderView2', // 仅为示例，并非真实的接口地址
    method: 'GET',
    data: {
       chooseId:chooseId
    },
    header: {
      'content-type': 'application/x-www-form-urlencoded' // 默认值
    },
    success(res) {
     wx.navigateTo({
       url: '../messageInformation/messageInformation',
     })
    },
    fail(res){
      wx.showToast({
        title: '网络连接失败，请重新尝试',
        icon:'none'
      })
    }
  })
},


/**
 * 生命周期函数--监听页面加载
 */


/**
 * 生命周期函数--监听页面初次渲染完成
 */
onReady: function () {

},

/**
 * 生命周期函数--监听页面显示
 */
onShow: function () {

},

/**
 * 生命周期函数--监听页面隐藏
 */
onHide: function () {

},

/**
 * 生命周期函数--监听页面卸载
 */
onUnload: function () {

},

/**
 * 页面相关事件处理函数--监听用户下拉动作
 */
onPullDownRefresh: function () {

},

/**
 * 页面上拉触底事件的处理函数
 */
onReachBottom: function () {

},

/**
 * 用户点击右上角分享
 */
onShareAppMessage: function () {

}
})